export class NewsModel {
  id?: string;        // 文章ID
  title?: string;     // 标题
  date?: string;      // 完整日期
  year?: string;      // 年份
  month?: string;     // 月份
  day?: string;       // 日期
  monthday?: string;  // 月份日期
  desc?: string;      // 简单描述
  content?: string;   // 完整内容

  toJson(): string {
    return JSON.stringify({
      id: this.id,
      title: this.title,
      date: this.date,
      year: this.year,
      month: this.month,
      day: this.day,
      monthday: this.monthday,
      desc: this.desc,
      content: this.content
    });
  }

  static fromJson(json: string): NewsModel {
    const obj = JSON.parse(json) as Record<string, unknown>;
    const model = new NewsModel();
    model.id = obj["id"] as string | undefined;
    model.title = obj["title"] as string | undefined;
    model.date = obj["date"] as string | undefined;
    model.year = obj["year"] as string | undefined;
    model.month = obj["month"] as string | undefined;
    model.day = obj["day"] as string | undefined;
    model.monthday = obj["monthday"] as string | undefined;
    model.desc = obj["desc"] as string | undefined;
    model.content = obj["content"] as string | undefined;
    return model;
  }
}